<?php

namespace app\admin\model\vactivities;

use think\Db;
use think\Model;


class Seriesactivity extends Model
{



    const SERIES_STATUS_0 = 0;//下架
    const SERIES_STATUS_1 = 1;//上架
    

    // 表名
    protected $name = 'series_activity';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
       // 'category_text',
        'status_text',
    ];


    //新加状态字段
    public function getStatusList()
    {
        return ['0' => __('series_status 0'),'1' => __('series_status 1')];
    }
    //获取状态字段
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


//    public function getCategoryList(){
//        $list = $this->getModel()->field(['id','name'])->select();
//        $list = collection($list)->toArray();
//        $Arr = [];
//        if($list){
//            foreach($list as $k=>$v){
//                $Arr[$k]['id'] = $v['id'];
//                $Arr[$k]['name'] = ($v['name']);
//            }
//        }
//        unset($list);
//        return $Arr;
//    }



    public function getSeriesList($admin_id=''){
        $where['status'] = self::SERIES_STATUS_1;
        if(!empty($admin_id)){
            $where['admin_id'] = $admin_id;
        }
        $list = $this->getModel()->where($where)->select();
        $list = collection($list)->toArray();
        $Arr = [];
        if($list){
            foreach($list as $k=>$v){
                $Arr[$v['id']] = $v['name'];
            }
        }
        unset($list);
        return $Arr;
    }


    public function getseriesNameById($id){
        $res = Db::name('series_activity')->where('id',$id)->field('name')->find();
        if($res){
            $name = $res['name'];
        }else{
            $name = '';
        }
        return $name;
    }

    /*
     *  获取系列信息
     *  $serid 系列i在
     */
    public function getSeriesInfo($serid){

        $res = Db::name('series_activity')->where('id',$serid)->field('*')->find();
        if($res){
            return $res;
        }else{
           return '';
        }
    }

}
